/*
* Copyright (C) 2012 Project-Storm <http://projectstorm-bki.blogspot.com/>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/


#include <nibobee/iodefs.h>
#include <nibobee/led.h>
#include <nibobee/sens.h>

void LED_ACTION(int led)
{
	led_init();
    for (int itr = 0; itr<10; itr++)
	{
        led_set(led, 1);
		delay(50);
		led_set(led,0);
		delay(50);
	}  
}

void LED_PARTY()
{
	led_init();
	for(int itrTime = 40; itrTime >= 1; itrTime -= 2)
	{
         for(int itrLED = 0; itrLED <=3; itrLED++)
		 {
              led_set(itrLED,1);
			  delay(5*itrTime);
			  led_set(itrLED,0);
			  delay(5*itrTime);
		 }
	}

	for(int itr = 0; itr < 200; itr++)
	{
	     for(int itrLED = 0; itrLED <=3; itrLED++)
		 {
              led_set(itrLED,1);
			  delay(20);
			  led_set(itrLED,0);
			  delay(20);
		 }
	}
}

int main()
{ 
	sens_init();
	int led1 = 0;
	int led2 = 0;
	int led3 = 0;
	int led4 = 0;

	while(1==1)
	{
	   int8_t status_L = sens_getLeft();
	   int8_t status_R = sens_getRight();
	   

	   if(led1 == 1 && led2 == 1 && led3 == 1 && led4 == 1)
	   {
	      LED_PARTY();
          led1 = 0;
	      led2 = 0;
	      led3 = 0;
	      led4 = 0;
       }

	   switch (status_L)
	   {
          case +1: 
		      LED_ACTION(0); 
			  led1 = 1;
			  break;
          case -1:
		      LED_ACTION(1);
			  led2 = 1;
			  break;
       }

	   switch (status_R)
	   {
          case +1: 
		      LED_ACTION(2); 
			  led3 = 1;
			  break;
          case -1:
		      LED_ACTION(3);
			  led4 = 1;
			  break;
       }

    }
    return 0;
}
